package com.grapefruitchat.client.ui;

import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.Toolkit;

import javax.swing.JFrame;

import com.grapefruitchat.client.GrapefruitChat;

/**
 * The main application window GUI component.
 * 
 * @author Michael Gierasimiuk, Innovation Science Pty Ltd.
 */
public class ApplicationWindow extends JFrame
{
  /**
   * Creates a new {@link ApplicationWindow}.
   */
  public ApplicationWindow()
  {
    this.setLayout( new GridBagLayout() );
    this.setTitle( "Grapefruit Chat" );
  }
  
  /**
   * Positions the {@link ApplicationWindow} in the centre of the screen. This
   * method should be called once the size of the frame has been set.
   */
  public void centerWindow()
  {
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    
    int w = this.getSize().width;
    int h = this.getSize().height;
    
    int x = ( screen.width - w ) / 2;
    int y = ( screen.height - h ) / 2;
    
    this.setLocation( x, y );
  }
  
  /**
   * Returns true if {@link GrapefruitChat} is being executed on a machine
   * running OS X.
   * 
   * @return true if the application is being executed on OS X.
   */
  public boolean isOsx()
  {
    String osName = System.getProperty( "os.name" );
    if ( osName.toLowerCase().contains( "mac" ) )
    {
      return true;
    }
    return false;
  }
}
